package com.cjx.yuanshenstartforumbackend.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.injector.methods.SelectList;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cjx.yuanshenstartforumbackend.common.BaseResponse;
import com.cjx.yuanshenstartforumbackend.common.ResultUtils;
import com.cjx.yuanshenstartforumbackend.domain.ArticleCategory;
import com.cjx.yuanshenstartforumbackend.domain.vo.ArticleCategoryVo;
import com.cjx.yuanshenstartforumbackend.mapper.ArticleCategoryMapper;
import com.cjx.yuanshenstartforumbackend.service.ArticleCategoryService;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.function.Function;

/**
* @author cjx
* @description 针对表【article_category(文章类别表)】的数据库操作Service实现
* @createDate 2023-12-23 11:07:53
*/
@Service
public class ArticleCategoryServiceImpl extends ServiceImpl<ArticleCategoryMapper, ArticleCategory>
    implements ArticleCategoryService {

    @Override
    public BaseResponse<HashMap<String, List<ArticleCategoryVo>>> getCategory() {
        List<ArticleCategory> list = list();
        if (list == null){
            throw new RuntimeException();
        }
        List<ArticleCategoryVo> safeList = new ArrayList<>();
       for (ArticleCategory articleCategory : list){
           safeList.add(BeanUtil.copyProperties(articleCategory,ArticleCategoryVo.class));
       }
        HashMap<String, List<ArticleCategoryVo>> result = new HashMap<>();
       result.put("ArticleType",safeList);
        return ResultUtils.success(result);
    }
}




